import java.util.*;

public class Main{
    public static void main1(String[] args){
        Scanner sc = new Scanner(System.in);
        StringBuilder ans = new StringBuilder();
        int m = sc.nextInt();
        int n = sc.nextInt();
        if(m == 0){
            System.out.println(0);
            return;
        }
        while(m != 0){
            int tmp = m % n;
            if(tmp > 9){
                tmp -= 10;
                ans.append((char)tmp + 'A');
                System.out.println(ans.toString());
            }else{
                ans.append(tmp);
            }
            m /= n;
        }
        ans.reverse();
        System.out.println(ans.toString());
    }

    public static void main2(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        StringBuilder sb1 =  new StringBuilder(s1);
        StringBuilder sb2 =  new StringBuilder(s2);
        int cnt = 0;
        for(int i = 0; i <= s1.length(); i++){
            StringBuilder tmp = new StringBuilder(sb1.substring(0, i));
            tmp.append(sb2);
            tmp.append(sb1.substring(i, sb1.length()));
            StringBuilder cmp = new StringBuilder(tmp);
            tmp.reverse();
            //System.out.println(tmp + " " + cmp);
            if(check(tmp, cmp)){
                cnt++;
            }
        }
        System.out.println(cnt);
    }

    private static boolean check(StringBuilder tmp, StringBuilder cmp) {
        for(int i = 0; i < tmp.length(); i++){
            if(tmp.charAt(i) != cmp.charAt(i)){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = sc.nextInt();
        }
        int[] sum = new int[n];
        sum[0] = arr[0];
        long ans = sum[0];
        for(int i = 1; i < n; i++){
            sum[i] = sum[i - 1] + arr[i];
            ans = Math.max(ans, sum[i]);
        }


        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                ans = Math.max(ans, sum[j] - sum[i]);
            }
        }
        System.out.println(ans);
    }

}